import React from "react";
import "./head.css";
import {addItemAction} from '../store/actionCreators'
// 连接器
import { connect } from "react-redux";
const Head = props => {
  let handleEnter = ({ keyCode, target }) => {
    // 判断事件触发就派发事件
    if (keyCode === 13) {
      props.addItem(target.value)
    }
  };
  return (
    <header className="common-header">
      <h1>TODOLIST</h1>
      <input type="text" onKeyUp={handleEnter} />
    </header>
  );
};
const mapDispatchToProps = dispatch => {
  return {
    addItem(value) {
      dispatch(addItemAction(value))

    }
  };
};
export default connect(null, mapDispatchToProps)(Head);
